/*
 * @Author: lp
 * @Date: 2022-01-24 11:53:19
 * @LastEditTime: 2022-04-15 15:39:26
 * @LastEditors: Please set LastEditors
 * @Description: 岗位权限
 * @FilePath: \nien-vue3-admin\src\directive\hasRole.ts
 */
import userStore from '@/store/modules/user'

export default {
  mounted(el, binding) {
    const { value } = binding
    const superAdmin = 'admin'
    if (value && value instanceof Array && value.length > 0) {
      const hasRole = userStore().roles.some((role) => superAdmin == role || value.includes(role))
      !hasRole && el.parentNode && el.parentNode.removeChild(el)
    } else {
      throw new Error('请设置角色权限标签')
    }
  },
}
